import pyaudio
import wave
import time

# 设置录音参数
sampling_buffer_size = 10000
sampling_format = pyaudio.paInt16
sampling_channels = 1
sampling_rate = 16000
# 录音长度
sampling_during = 5
audio_save_name = "record1.wav"
total_stream_frames = []

def my_call_back(in_data,frame_count,time_info,status):
    print('*'*50)
    print('in_data:',in_data)
    print('frame_count:',frame_count)
    print('time_info:',time_info)
    print('status:',status)

    return (in_data,pyaudio.paContinue)

def main():
    p = pyaudio.PyAudio()
    stream = p.open(format=sampling_format,
                          channels=sampling_channels,
                          rate=sampling_rate,
                          input=True,
                          frames_per_buffer = sampling_buffer_size,
                          stream_callback=my_call_back)

    stream.start_stream()
    while stream.is_active():
        pass

    stream.stop_stream()
    stream.close()
    p.terminate()

if __name__ == '__main__':
    from threading import Timer

    main()